package com.offcn.dao;

import com.offcn.entity.Course;
import com.offcn.entity.CourseUser;
import com.offcn.entity.User;
import com.offcn.utils.LIstUtils;
import com.offcn.utils.PageTool;

import java.util.List;

/**
 * @author xyll1
 */
public class CourseUserDao extends BaseDao<CourseUser>{
    //获取模糊查询后的总数据量
    public List<Object> selectUidsByName(String search) {
        return singLeColumn("select uid from user where name like '%"+search+"%'");
    }
    //获取模糊查询后的数据
    public int selectTotalCount(List<Object> uids) {
        String sql ="select count(*) from course_user ";
        if (uids !=null && uids.size()>0){
            sql += "where uid in ("+ LIstUtils.listToString(uids) +") ";
        }
        long singLeData = (long)singLeData(sql);
        return (int) singLeData;

    }

    //获取模糊查询的uid/sid值
    public List<CourseUser> findAllCourseUser(PageTool pageTool, List<Object> uids) {
        String sql = "select * from course_user ";
        if (uids !=null && uids.size()>0){
            sql += " where uid in ("+ LIstUtils.listToString(uids) +") ";
        }     sql+=" limit ?,?";
        return moreline(sql, CourseUser.class,pageTool.getStartIndex(),pageTool.getPageSize());
    }

    public int updateCourseUser(String id, String cid) {
        return dml("update course_user set cid = ? where id = ?",cid,id);
    }

    public int deleteAllCourseUser(String ids) {
        return dml("delete from course_user where id in("+ids+")");
    }
}
